package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingElderDto;
import com.zzyl.dto.RetreatApplicationDto;
import com.zzyl.dto.RetreatReqDto;
import com.zzyl.service.CheckoutService;
import com.zzyl.service.ElderService;
import com.zzyl.service.RetreatService;
import com.zzyl.vo.retreat.ElderVo;
import com.zzyl.vo.retreat.TasVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 客户老人关联 Controller
 */
@RestController
@RequestMapping("/elder")
@Api(tags = "老人")
public class ElderController {

    @Resource
    private ElderService elderService;

    @Autowired
    private CheckoutService checkoutService;
    @Autowired
    private RetreatService retreatService;

    /**
     * 列表
     */
    @GetMapping("/selectList")
    @ApiOperation(value = "列表")
    public ResponseResult selectList() {
        List<ElderVo> elderVos = elderService.selectList();
        return ResponseResult.success(elderVos);
    }

    /**
     * 选择老人列表
     */
    @GetMapping("/selectListByPage")
    @ApiOperation(value = "选择老人列表")
    public ResponseResult selectListByPage(@RequestParam(required = false) String name,
                                           @RequestParam(required = false) String idCardNo,
                                           @RequestParam(required = false, defaultValue = "1") Integer pageNum,
                                           @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        PageResponse pageResponse = elderService.selectListByPage(name, idCardNo, pageNum, pageSize);
        return ResponseResult.success(pageResponse);
    }

    /**
     * 设置护理员
     *
     * @param nursingElders
     */
    @PutMapping("/setNursing")
    @ApiOperation(value = "设置护理员", notes = "设置护理员")
    public ResponseResult setNursing(@RequestBody List<NursingElderDto> nursingElders) {
        elderService.setNursing(nursingElders);
        return ResponseResult.success();
    }

    @GetMapping("/selectByIdCard")
    @ApiOperation(value = "身份证号", notes = "身份证号")
    public ResponseResult selectByIdCard(@RequestParam String idCard) {
        return ResponseResult.success(elderService.selectByIdCard(idCard));
    }

    //申请退住
    @PostMapping("/create")
    @ApiOperation(value = "申请退住", notes = "申请退住")
    public ResponseResult createRetreat(@RequestBody RetreatApplicationDto dto) {
        return checkoutService.createCheckOut(dto);
    }

    /**
     * 退住表单查询
     *
     * @param flowStatus  流程状态（0:申请退住，1:申请审批，2:解除合同，3:调整账单，4:账单审批，5:退住审批，6:费用算清）
     * @param retreatCode 退住编号
     * @param taskId      任务ID
     * @param assigneeId  当前处理人ID
     * @return 退住表单
     */
    @GetMapping
    public ResponseResult<TasVo> getRetreat(Integer flowStatus, String retreatCode, String taskId, String assigneeId) {
        return retreatService.getRetreat(flowStatus, retreatCode, taskId, assigneeId);
    }

    /**
     * 退住管理
     *
     * @param reqDto 请求参数
     * @return 退住列表
     */
    @PostMapping("/selectByPage")
    @ApiOperation(value = "退住管理")
    public ResponseResult selectByPage(@RequestBody RetreatReqDto reqDto) {
        return retreatService.selectByPage(reqDto);
    }
}


